$(function(){
	ShowTabl();
});
function GiveValueSel(){
	ShowTabl();
}

function ShowTabl(){
	//获取用户姓名
	var user = document.getElementById("userid").value;
	//alert(user);
	user=encodeURI(encodeURI(user));
	var url = "givevalue/all.do?account="+user;
	
	var tableSource = new $.jqx.dataAdapter({
		dataType: "json",
		dataFields:[
		    { name: "id",type:"int"},
		    { name: "uid",type:"string"},
		    { name: "account",type:"string"},
		    { name: "name", type: "string" },
		    { name: "money", type: "float" },
		    { name: "order_sn", type: "string" },
		    { name: "order_time", type: "date" },
		    { name: "pay_code", type: "string" },
		    { name: "trade_sn",type: "string"},
		    { name: "trade_status",type:"int"},
		    { name: "trade_time",type:"date"},
		    { name: "order_status",type:"int"},
		    { name: "audit_person",type:"string"},
		    { name: "bz",type:"bz"}
		],
		id: "id",
		url:url
	});
	ShowTableData(tableSource);
	
}
function ShowTableData(tableSource){
	$("#dataTable").jqxDataTable({
		width: "100%",
        source: tableSource,
        pageable: true,
        pageSize: 20,
        serverProcessing: true,
        pagerButtonsCount: 10,
        columnsResize: true,
        sortable: true,
        columns: [
            { text: "序号", width: 50, cellsRenderer: function(row) { return (row + 1).toString(); } },
            { text: "账号",dataField:"account"},
            { text: "用户名",dataField:"name"},
            { text:	"金额",dataField:"money"},
            { text: "订单号",dataField:"order_sn"},
            { text: "时间",dataField:"order_time",
            	cellsRenderer: function(row, column, value, rowData) {
            		return format(value, "Y-M-D H:I");
            	}
            },
            { text: "支付方式",dataField:"pay_code"},
            { text: "操作人",dataField:"audit_person"},
            { text:"备注",dataField:"bz"}
        ],
	});
}
function ShowAddPage(){
	_editerIndex = layer.open({
		id: "addMoney",
		title: "添加充值",
	    type: 1,
	    skin: "layui-layer-rim",
	    area: ["660px", "300px"],
	    content:'<form id="rolelist-editer" class="form" method="post" style="height: 100%;overflow: auto;">'+
	    		'<div id="role-editer" class="form" style="height: 60px;overflow: auto;">' +
	    		//用户名
				'<label class="from-label update" style = "width:100px" for="account">用户名：</label>'+
	    		'<input id = "account" type="text" style = "width:180px" name="account" allowBlank="false" class="form-control" placeholder="请输入用户名" />'+
	    		//充值金额
	    		'<label class="from-label update" style = "width:100px" for="money">金额：</label>'+
	    		'<input id = "money" type="text" style = "width:180px" name="money" allowBlank="false" class="form-control" placeholder="单位：元" />'+
	    		'</div>' +
	    		'<div id="role-editer" class="form" style="height: 60px;overflow: auto;">' +
	    		//第三方订单号
				'<label class="from-label update" style = "width:100px" for="trade_sn">第三方交易号：</label>'+
	    		'<input id = "trade_sn" type="text" style = "width:180px" name="trade_sn" allowBlank="false" class="form-control" placeholder="请输入第三方订单号" />'+
	    		//备注
				'<label class="from-label update" style = "width:100px" for="czbz">备注：</label>'+
				'<input id = "czbz" type="text" style = "width:180px" name="czbz" allowBlank="false" class="form-control" placeholder="备注" />'+
	    		
				//'<input id = "czbz" type="text" style = "width:180px" name="czbz" allowBlank="false" class="form-control" placeholder="备注" />'+
	    		'</div>' +
	    		'<div id="role-editer" class="form" style="height: 60px;overflow: auto;">' +
	    		//密码
				'<label class="from-label update" style = "width:100px" for="password">密码：</label>'+
				'<input id = "password" type="password" style = "width:180px" name="password" allowBlank="false" class="form-control" placeholder=""/>'+
	    		'</div>' +
	    		'</form>'+
	    		'<div class="form" style="position: absolute;bottom: 0px;width: 100%;text-align: right;background-color: #DDD;">' +
				'<input type="button" class="btn btn-sm btn-success" onclick="Addmoney(this)" value="充值"/>' +
				'<input type="button" class="btn btn-sm btn-info" onclick="closeEditer(this)" value="取消"/>' +
				'</div>',
	    	});
}

function Addmoney(obj){
	//获取填写值
	var account = document.getElementById("account").value;
	var money = document.getElementById("money").value;
	var trade_sn = document.getElementById("trade_sn").value;
	var bz = document.getElementById("czbz").value;
	//alert(bz);
	//bz=encodeURI(encodeURI(bz));
	var password = document.getElementById("password").value;
	$.ajax({
		url:"givevalue/addGiveValue.do",
		data:{account:account,
			money:money,
			trade_sn:trade_sn,
			password:password,
			bz:bz},
		async: true,
		type:"post",
		success:function(data){
			if(data.code == 1){
				layer.msg("充值成功");
				closeEditer(obj);
			}else if(data.code == 2){
				layer.msg("钱包入账失败");
			}else if(data.code == 99){
				layer.msg("设置支付点数失败：管理员密码错误");
			}else{
				layer.msg(data.msg);
			}
		}
	});
		
	/*		"/manager/givevalue/addGiveValue.do", {
		account:account,
		money:money,
		trade_sn:trade_sn,
		password:password,
		bz:bz
	},function(data) {
		if(data.code == 1){
			layer.msg("充值成功");
			closeEditer(obj);
		}else if(data.code == 2){
			layer.msg("钱包入账失败");
		}else if(data.code == 99){
			layer.msg("设置支付点数失败：管理员密码错误");
		}else{
			layer.msg(data.msg);
		}
	});*/
}


